<template>
	<view class="create-assets-account block">
		<view class="account-name"><text>账户名称</text></view>
		<uni-easyinput trim="all" v-model="form.accountName"></uni-easyinput>

		<view v-if="['信用卡','储蓄卡'].includes(type)" class="account-name">
			<text>银行名称</text>
		</view>
		<uni-easyinput v-if="['信用卡','储蓄卡'].includes(type)" trim="all" v-model="form.bankName"></uni-easyinput>

		<view class="account-name"><text>账户金额</text></view>
		<uni-easyinput trim="all" v-model="form.balance"></uni-easyinput>

		<view class="account-name"><text>备注</text></view>
		<uni-easyinput trim="all" v-model="form.remarks"></uni-easyinput>

		<view class="save-btn" @click="save">

			<text class="save-btn-text">保存 </text>
		</view>
	</view>
</template>

<script setup lang="ts">
	import { ref } from 'vue'
	import { onLoad } from '@dcloudio/uni-app'
	import { assetsApi } from "@/apis/apis"
	const type = ref('')

	interface QueryParams {
		type ?: string
	}

	onLoad((query : QueryParams) => { // TypeScript 类型声明
		type.value = query.type
		console.log('参数:', query)
	})

	const SysUser = JSON.parse(uni.getStorageSync('SysUser') || '{}')
	const form = ref({
		accountName: '',
		bankName: '',
		balance: '',
		remarks: "",
		categoryName: type.value,
		categoryId: '',
		userId: SysUser.id
	})

	const save = async () => {
		const res : any = await assetsApi.addUsingPOST_2(form.value)
		if (res.code === 200) {
			uni.showToast({ title: res.msg, icon: 'success' })
			uni.navigateBack()
		}
	}
</script>

<style lang="scss">
	.block {}

	.create-assets-account {
		height: 100%;
		padding: 10px 20px 0;

		.account-name {
			margin-top: 15px;
			margin-bottom: 15px;
		}


	}
</style>